<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<!--<base href="http://localhost:8080/">-->
		<base href=".">
		
		<title>主页</title>
		<meta name="robots" content="noindex,nofllow">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		
		<!--<base href="http://localhost:8080/">-->
		<base href=".">
		
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
		<link rel="icon" href="favicon.ico" mce_href="favicon.ico" type="image/x-icon">
		<link rel="shortcut icon" href="favicon.ico" mce_href="favicon.ico" type="image/x-icon">
		
		<script type="text/javascript" src="./js/jquery1113.js"></script>
		<script src="js/mui.min.js"></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		
		
		<script type="text/javascript" src="./js/jquery1113.js"></script>
		<link href="./css/bootstrap.min.css" rel="stylesheet">
		<link href="./css/bootstrap-theme.min.css" rel="stylesheet">
		<script src="./js/bootstrap.min.js"></script>
		<script src="./js/data.js"></script>
		<link href="./css/web-base.css" rel="stylesheet">
		<script type="text/javascript">
		</script>
		<script src="./js/base64.js"></script>
		<script src="./js/md5.js"></script>
		<script src="./js/encode.provider.js"></script>
		<style>
			.mui-popup {
			  border-radius: 0;
			}
			.mui-popup-inner {
			  border-radius: 0;
			}
		</style>
	</head>

	<body style="overflow-y: hidden;">
		<div id="loginCheck" class="containerbox" style="margin-top: 100px;">
			<div class="container ">
				<div
					style="box-shadow: 0px 0px 50px 15px rgba(0, 0, 0, 0.1); margin: auto; border-radius: 6px 6px 6px 6px; max-width: 800px; border: 1px solid #e7e7e7; margin-top: 30px; margin-bottom: 100px; background-color: #fcfcfc;">
					<div class="panel-body" style="padding: 0px;">
						<div class="row">
							<div class="col-md-6" style="padding: 50px; padding-top: 10px; padding-bottom: 20px;">
		
								<h1 style="color: #666; font-size: 24px; font-weight: 700;">
									<img src="images/logo.png" width="32px" height="32px;" style="margin-bottom: 5px;">
									<span>法治公主岭</span>
								</h1>
								<hr>
								<form class="form-signin" role="form" id="loginFormId" action="" method="post">
									<div class="form-group">
										<label for="exampleInputEmail1"> 登录名 </label> <input type="text"
											class="form-control" placeholder="手机/邮箱/用户登录名" value=""
											style="margin-top: 4px;" id="loginNameId" name="name" required=""
											autofocus="">
									</div>
									<div class="form-group">
										<label for="exampleInputEmail1"> 登录密码 </label> <input type="password"
											class="form-control" placeholder="请录入密码" style="margin-top: 4px;"
											id="loginPassWId" required=""> <input name="password" type="hidden"
											id="realPasswordId">
									</div>
									<!-- <div class="form-group">
										<label for="exampleInputEmail1">验证码</label>
										<div class="input-group">
											<input type="text" class="form-control" placeholder="请录入验证码"
												id="checkcodeId" name="checkcode">
											<div class="input-group-addon" style="padding: 0px;">
												<img id="checkcodeimgId"
													style="cursor: pointer; height: 30px; width: 100px;"
													src="" />
											</div>
										</div>
									</div> -->
									<!-- <input type="hidden" name="url" id="loginUrlId"> -->
									<div>
										<button class="btn btn-danger text-left" id="loginButtonId"
											style="margin-top: 4px; width: 100%;" type="button">登录</button>
									</div>
								</form>
		
								<div class="text-center" id="alertMessageErrorId"
									style="margin: 4px; color: red; border-top: 1px dashed rgb(204, 204, 204); padding-top: 20px; display: none;">
								</div>
							</div>
							<div class="col-md-6 hidden-xs hidden-sm "
								style="border-left: 1px solid #e7e7e7; padding-left: 0px;">
								<div style="height: 450px; overflow: hidden; border-radius: 0px 6px 6px 0px;">
									<img alt="" height="450px" src="./img/colors.jpg">
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="container-fluid" style="padding: 0px;">
			<div class="container-fluid" style="background-color: #f8fafc;">
				<div class="container">
					<div class="row">
						<div class="col-md-12">
							<div style="height: 100px; padding: 50px; text-align: center; color: #99a1a6;">
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<iframe id="wlp" sandbox="allow-scripts allow-same-origin allow-forms" src="" style="width:100%;display: none;"allowfullscreen="allowfullscreen" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" webkitallowfullscreen="webkitallowfullscreen"></iframe>
		<script src="js/util.js"></script>
		<script src="js/openView.js"></script>
		<script type="text/javascript">
			(function() {
				var name = "";
				var password = "";
				mui.init({
					swipeBack: true //启用右滑关闭功能
				});
				mui.plusReady(function() {
					var bRet = true;
					
					var self = plus.webview.currentWebview();
					// leftPos = Math.ceil((window.innerWidth - 60) / 2); // 设置凸起大图标为水平居中

					// /**	
					//  * drawNativeIcon 绘制带边框的半圆，
					//  * 实现原理：
					//  *   id为bg的tag 创建带边框的圆
					//  *   id为bg2的tag 创建白色矩形遮住圆下半部分，只显示凸起带边框部分
					//  * 	 id为iconBg的红色背景图
					//  *   id为icon的字体图标
					//  *   注意创建先后顺序，创建越晚的层级越高
					//  */
					// var drawNativeIcon = util.drawNative('icon', {
					// 	bottom: '5px',
					// 	left: leftPos + 'px',
					// 	width: '60px',
					// 	height: '60px'
					// }, [{
					// 	tag: 'rect',
					// 	id: 'bg',
					// 	position: {
					// 		top: '1px',
					// 		left: '0px',
					// 		width: '100%',
					// 		height: '100%'
					// 	},
					// 	rectStyles: {
					// 		color: '#fff',
					// 		radius: '50%',
					// 		borderColor: '#ccc',
					// 		borderWidth: '1px'
					// 	}
					// }, {
					// 	tag: 'rect',
					// 	id: 'bg2',
					// 	position: {
					// 		bottom: '-0.5px',
					// 		left: '0px',
					// 		width: '100%',
					// 		height: '45px'
					// 	},
					// 	rectStyles: {
					// 		color: '#fff'
					// 	}
					// }, {
					// 	tag: 'rect',
					// 	id: 'iconBg',
					// 	position: {
					// 		top: '5px',
					// 		left: '5px',
					// 		width: '50px',
					// 		height: '50px'
					// 	},
					// 	rectStyles: {
					// 		color: '#d74b28',
					// 		radius: '50%'
					// 	},
					// }, {
					// 	tag: 'font',
					// 	id: 'icon',
					// 	text: '扫一扫', //此为字体图标Unicode码'\e600'转换为'\ue600'
					// 	position: {
					// 		top: '0px',
					// 		left: '5px',
					// 		width: '50px',
					// 		height: '100%'
					// 	},
					// 	textStyles: {
					// 		fontSrc: '_www/fonts/iconfont.ttf',
					// 		align: 'center',
					// 		color: '#fff',
					// 		size: '10px'
					// 	}
					// }]);
					// // append 到父webview中
					// self.append(drawNativeIcon);

					// //自定义监听图标点击事件
					// var active_color = '#fff';
					// drawNativeIcon.addEventListener('click', function(e) {
					// 	if(!bRet){
					// 		return;
					// 	}
					// 	if(name != '' && name != null && password != '' && password != null){
					// 		plus.webview.create('html/barcode.html', "barcode").show();
					// 	} else {
					// 		mui.alert('请先登录');
					// 	}
					// });
					// 中间凸起图标绘制及监听点击完毕

					// 创建子webview窗口 并初始化
					var aniShow = {};
					util.initSubpage(aniShow);
					
					var nview = plus.nativeObj.View.getViewById('tabBar'),
						activePage = plus.webview.currentWebview(),
						targetPage,
						subpages = util.options.subpages,
						pageW = window.innerWidth,
						currIndex = 0;
						
					/**
					 * 根据判断view控件点击位置判断切换的tab
					 */
					nview.addEventListener('click', function(e) {
						if(!bRet){
							return;
						}
						if(name != '' && name != null && password != '' && password != null){
							var clientX = e.clientX;
							if(clientX > 0 && clientX <= parseInt(pageW * 0.25)) {
								currIndex = 0;
							} else if(clientX > parseInt(pageW * 0.25) && clientX <= parseInt(pageW * 0.45)) {
								currIndex = 1;
							} else if(clientX > parseInt(pageW * 0.45) && clientX <= parseInt(pageW * 0.8)) {
								currIndex = 2;
							} else {
								currIndex = 3;
							}
							// 匹配对应tab窗口	
							if(currIndex > 0) {
								targetPage = plus.webview.getWebviewById(subpages[currIndex-1]);
							} else {
								targetPage = plus.webview.currentWebview();
							}
							
							if(targetPage == activePage) {
								return;
							}
							
							//底部选项卡切换
							util.toggleNview(currIndex);
							// 子页面切换
							util.changeSubpage(targetPage, activePage, aniShow);
							//更新当前活跃的页面
							activePage = targetPage;
							
						} else {
							util.toggleNview(0);
							util.changeSubpage(plus.webview.getLaunchWebview(), plus.webview.currentWebview(), {});
							activePage=plus.webview.getLaunchWebview()
							mui.alert('请先登录！');
						}
					});
					
					function checkUrl(appendUrl) {
						return serverUrl + appendUrl;
					}
					
					$('#alertMessageErrorId').hide();
					$('#loginButtonId')
						.bind(
							'click',
							function() {
								if ($('#loginNameId').val() &&
									$('#loginPassWId').val()) {
									//$('#loginUrlId').val(document.referrer);
									$('#loginButtonId').addClass("disabled");
									$('#loginButtonId').text("提交中...");
									$('#realPasswordId').val($('#loginPassWId').val());
									formSubmit();
								} else {
									$('#alertMessageErrorId').show();
									$('#romovealertMessageErrorId').hide();
									$('#alertMessageErrorId')
										.html(
											'请输入用户名/密码');
								}
							});
					$('#loginNameId').keydown(function(e) {
						if (e.keyCode == 13) {
							//$('#loginUrlId').val(window.location.href);
							$('#loginButtonId').click();
						}
					});
					$('#loginPassWId').keydown(function(e) {
						if (e.keyCode == 13) {
							//$('#loginUrlId').val(window.location.href);
							$('#loginButtonId').click();
						}
					});
					$('#checkcodeId').keydown(function(e) {
						if (e.keyCode == 13) {
							//$('#loginUrlId').val(window.location.href);
							$('#loginButtonId').click();
						}
					});
					function formSubmit() {
						var formData = $("#loginFormId").serializeArray(); // 获取表单数据并转换为数组
						var jsonObject = {};
						$.each(formData, function(index, field) {
							jsonObject[field.name] = field.value;
							if(field.name=="name"){
								name = field.value;
							}
							if(field.name=="password"){
								password = field.value;
							}
						});
					
						xhr = new plus.net.XMLHttpRequest();
						xhr.onreadystatechange = function() {
							switch (xhr.readyState) {
								case 4:
									if (xhr.status == 200) {
										var data = JSON.parse(xhr.responseText);
										if (data && data.result == 1) {
											plus.storage.setItem('name', name);
											plus.storage.setItem('password', password);
											checkLoginStatus();
										} else {
											$('#loginButtonId').removeClass("disabled");
											$('#loginButtonId').text("登录");
											$('#alertMessageErrorId').show();
											$('#romovealertMessageErrorId').hide();
											if (data.message) {
												$('#alertMessageErrorId').html(data.message);
											} else {
												$('#alertMessageErrorId').html('系统错误，请稍后重试');
											}
										}
					
									} else {
										console.log("xhr请求失败：" + xhr.readyState);
									}
									break;
								default:
									break;
							}
						}
						console.log(serverUrl + "reson/Pubwebsubmit.do")
						xhr.open("POST", serverUrl + "reson/Pubwebsubmit.do") ;
						xhr.setRequestHeader("Content-Type", "application/json");
						xhr.send(JSON.stringify(jsonObject));
					}
					
					
					$(function(){
						name = plus.storage.getItem('name');
						password = plus.storage.getItem('password');
						if(name!=null && name != '' && password != null && password != ''){
							$("#loginNameId").val(name);
							$("#realPasswordId").val(password);
							formSubmit();
						}
						getVersion();
					});
					
					function checkLoginStatus(){
						$(".containerbox").css("display","none");
						$(".container-fluid").css("display","none");
						setTimeout(function() {
							//收缩键盘页面变形 这里延迟500毫秒给键盘收缩
						    $("#wlp").attr("src",serverUrl + "login/PubLogin.do?name="+name+"&password="+password);
						    $("#wlp").css("height",$(document).height());
						    $("#wlp").show();
						}, 500);
					}
					
					function getVersion(){
						xhr = new plus.net.XMLHttpRequest();
						xhr.onreadystatechange = function() {
							if (xhr.readyState == 4 && xhr.status == 200) {
								console.log(version)
								var data = JSON.parse(xhr.responseText);
								if (data && data.result == 1) {
									var nVersion = data.version;
									if(nVersion !== version){
										bRet = false;
										// alert("请更新");
										var btnArray = [ '确定更新'];
										mui.confirm('检测到新版本！请更新', '版本检测', btnArray, function(e) {
											if (e.index == 0) {
												mui.confirm('<p class="mui-progressbar mui-progressbar-infinite"></p>', '更新中...', [], function(e) {
												},'div')
												if(data.updateUrl){
													update(data.updateUrl);
												}
											}
										})
									}
								} else {
									mui.alert(data.message);
								}
							}
						}
						xhr.open("POST", serverUrl + "reson/PubGetVersion.do");
						xhr.setRequestHeader("Content-Type", "application/json");
						xhr.send();
					}
				});
				
				
				function update(url){
					
					// plus.runtime.openURL(url);
					var downloadUrl = url; // 要下载的文件 URL
					
					//创建下载任务
					var downloadTask = plus.downloader.createDownload(downloadUrl, {
					  method: "GET"
					});
					
					// 监听下载任务的 completed 事件
					// downloadTask.addEventListener("statechanged", function(download, status) {
					//   // console.log("下载状态变化：" + download.state);
					//     if (download.state === 4) { // 下载任务已完成
					//       if (status === 200) {
					//         var filePath = download.filename; // 下载完成后保存的文件路径
					// 		// console.log(filePath);
					//         // 使用系统默认程序打开文件
					//         plus.runtime.openFile(filePath, {}, function(error) {
					//           console.log("打开文件失败：" + error.message);
					//         });
					//       } else {
					//         console.log("下载失败：" + status);
					//       }
					//     }
					// });
					
					//监听下载任务的 statechanged 事件
					downloadTask.addEventListener("statechanged", function(download, status) {
					  var progress = Math.round(download.downloadedSize / download.totalSize * 100); // 计算下载进度
					  console.log("下载进度：" + progress + "%");
					  // if(progress===100){
						 //  console.log(download.filename);
						 //  plus.runtime.openFile(download.filename, {}, function(error) {
						 //    console.log("打开文件失败：" + error.message);
						 //  });
					  // }
					});
					
					downloadTask.addEventListener("statechanged", function(download, status) {
					  // console.log("下载状态变化：" + download.state);
					
					  if (download.state === 4) { // 下载任务已完成
					    if (status === 200) {
					      var filePath = download.filename; // 下载完成后保存的相对路径
					
					      // 将相对路径转换为绝对路径
					      plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
					        var absPath = entry.toLocalURL(); // 获取文件的绝对路径
					        // console.log("文件的绝对路径：" + absPath);
					
					        // 使用系统默认程序打开文件
					        plus.runtime.openFile(absPath, {}, function(error) {
					          console.log("打开文件失败：" + error.message);
					        });
					      }, function(error) {
					        console.log("获取文件路径失败：" + error.message);
					      });
					    } else {
					      console.log("下载失败：" + status);
					    }
					  }
					});
					
					// 开始下载任务
					downloadTask.start();
				}
			})();
		</script>
	</body>

</html>